﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyDataGridView.Properties;

namespace MyDataGridView
{
    public partial class MyDataGridView : DataGridView
    {
        public MyDataGridView()
        {
            InitializeComponent();
     
            row = 0;
        }
        int row;
        protected Image backgroundImage = Properties.Resources.black;
        [Category("自定义"), Description("MyDataGridView背景图")]
        [Browsable(true)]
        public new Image BackgroundImage
        {
            get
            {
                return backgroundImage;
            }
            set
            {
                backgroundImage = value;
            }
        }

        protected Image headleft = Properties.Resources.headleft;
        protected Image head = Properties.Resources.head;
        protected Image headright = Properties.Resources.headright;
        protected Image heightleft = Properties.Resources.heightleft;
        protected Image height = Properties.Resources.height;
        protected Image heightright = Properties.Resources.heightright;
        protected Image cellleft = Properties.Resources.cellleft;
        protected Image cell = Properties.Resources.cell;
        protected Image cellright = Properties.Resources.cellright;

        protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds)
        {
            base.PaintBackground(graphics, clipBounds, gridBounds);
            if (backgroundImage != null)
                graphics.DrawImage(backgroundImage, gridBounds);

            //if (headleft != null)
            //    graphics.DrawImage(headleft, 0, 0, headleft.Width, headleft.Height);
            //if (headright != null)
            //    graphics.DrawImage(headright,Width - headright.Width,0,headright.Width,headright.Height);
            if (head != null)
                graphics.DrawImage(head, headleft.Width, 0, Width - headleft.Width - headright.Width, head.Height);
            
            //int c = this.RowCount;
            //for (int i = 0; i <= c; i++)
            //{
                //if (cellleft != null)
                //    graphics.DrawImage(cellleft, 0, i * 23, cellleft.Width, cellleft.Height);
                //if (cellright != null)
                //    graphics.DrawImage(cellright,Width - cellright.Width,i * 23,cellright.Width,cellright.Height);
                //if (cell != null)
                //    graphics.DrawImage(cell, cellleft.Width, i * 23, Width - cellleft.Width - cellright.Width,cell.Height);
            //}

            //if (height != null)
            //    graphics.DrawImage(height, 0, row * 23, Width,20);
        }

        protected override void OnSelectionChanged(EventArgs e)
        {
            base.OnSelectionChanged(e);
            row = this.CurrentRow.Index + 1;
        }

    }
}
